package cn.ken.student.rubcourse.service.impl;

import cn.ken.student.rubcourse.common.entity.Result;
import cn.ken.student.rubcourse.common.util.PageUtil;
import cn.ken.student.rubcourse.dto.req.NoticePageReq;
import cn.ken.student.rubcourse.entity.SysNotice;
import cn.ken.student.rubcourse.mapper.SysNoticeMapper;
import cn.ken.student.rubcourse.service.INoticeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 系统通知表 服务实现类
 * </p>
 *
 * @author Ken-Chy129
 * @since 2022-11-16
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements INoticeService {
    
    @Autowired
    private SysNoticeMapper sysNoticeMapper;

    @Override
    public Result getNoticePage(HttpServletRequest httpServletRequest, NoticePageReq noticePageReq) {
        LambdaQueryWrapper<SysNotice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(noticePageReq.getStudentId() != null, SysNotice::getStudentId, noticePageReq.getStudentId());
        List<SysNotice> sysNotices = sysNoticeMapper.selectList(queryWrapper);
        IPage<SysNotice> page = PageUtil.getPage(new Page<>(), noticePageReq.getPageNo(), noticePageReq.getPageSize(), sysNotices);
        return Result.success(page);
    }
}
